package com.xuexisheqv.auth.domain.service.impl;

import com.xuexisheqv.auth.common.enums.IsDeletedFlagEnum;
import com.xuexisheqv.auth.domain.convert.AuthPermissionBOConverter;
import com.xuexisheqv.auth.domain.convert.AuthRolePermissionBOConverter;
import com.xuexisheqv.auth.domain.entity.AuthPermissionBO;
import com.xuexisheqv.auth.domain.entity.AuthRolePremissionBO;
import com.xuexisheqv.auth.domain.service.AuthPermissionDomainService;
import com.xuexisheqv.auth.domain.service.AuthRolePermissionDomainService;
import com.xuexisheqv.auth.infra.basic.entity.AuthPermission;
import com.xuexisheqv.auth.infra.basic.entity.AuthRolePremission;
import com.xuexisheqv.auth.infra.basic.service.AuthRolePremissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

@Service
@Slf4j
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {


    @Resource
    private AuthRolePremissionService authRolePremissionService;

    @Override
    public Boolean add(AuthRolePremissionBO authRolePremissionBO) {
        List<AuthRolePremission> rolePremissionList = new LinkedList<>();
        Long roleId = authRolePremissionBO.getRoleId();
        authRolePremissionBO.getPermissionIdList().forEach((permissionId)->{
            AuthRolePremission authRolePremission = new AuthRolePremission();
            authRolePremission.setRoleId(roleId);
            authRolePremission.setPermissionId(permissionId);
            authRolePremission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            rolePremissionList.add(authRolePremission);
        });
        Integer count = authRolePremissionService.batchInsert(rolePremissionList);
        return count > 0;
    }

}
